@extends('layouts.home.layout')
@section('css')
    <link rel="stylesheet" href="/home/css/amazeui.min.css">
    <link rel="stylesheet" href="/home/css/com.css">
    <link rel="stylesheet" href="/home/css/main.css">
    <link rel="stylesheet" href="/home/css/loan.css">
@endsection
@section('content')
    <script src="/home/js/hm.js"></script>
    <script type="text/javascript" defer async src="/home/js/9712e432da63dc22.js"></script>
    <script type="text/javascript" src="/home/js/base2.js"></script>
    <script type="text/javascript" src="/home/js/xt.2.0.0.js"></script>
    <script src="/home/js/ddzf.util2.js"></script>
    <script src="/home/js/xxjrbtn.js"></script>

    @include('layouts.home._nav')

    <script type="text/javascript">
        //一次性还款
        function repayOneTime(amount, deadline, monthRate){
            var bean = {};
            bean.interestSum = Math.round(amount * deadline * monthRate / 100); // 总利息
            bean.sum = Math.round((bean.interestSum + amount)*100)/100;
            return bean;
        }

        // 先息后本
        function repayInterest(amount, deadline, monthRate){
            var bean = {};
            bean.perMonth = Math.round(amount * monthRate / 100);// 每月还款
            bean.interestSum = Math.round(bean.perMonth * deadline);// 总利息
            bean.lastMonth = bean.perMonth + amount; // 最后一个月
            bean.sum = Math.round((bean.interestSum + amount)*100)/100; // 本息总和
            return bean;
        }

        // 等额本息
        function repaySame(amount, deadline, monthRate){
            var bean = {};
            bean.perMonth = Math.round((amount * monthRate/100 * (Math.pow((1 + monthRate/100), deadline))
                            / (Math.pow((1 + monthRate/100), deadline) - 1)) * 100) / 100;// 每月还款额
            var repayInterest = 0;
            for (var i = 1; i <= deadline; i++) {
                // 每月利息额
                var monthinterestmoney = Math.round((amount * monthRate/100
                                * (Math.pow((1 + monthRate/100), deadline) - Math.pow((1 + monthRate/100), (i - 1)))
                                / (Math.pow((1 + monthRate/100), deadline) - 1)) * 100) / 100;
                var principalmoney = bean.perMonth - monthinterestmoney;
                repayInterest += (bean.perMonth - principalmoney);
            }
            bean.interestSum = Math.round(repayInterest * 100) / 100; // 总利息
            bean.sum = Math.round((bean.interestSum + amount)*100)/100;; // 本息总和
            return bean;
        }

        // 等额本金
        function repaySamePrincipal(amount, deadline, monthRate){
            var bean = {};
            var monthPrincipal = amount / deadline;//每月本金
            var repayInterest = 0;
            var firstInterest = 0;
            for(var i = 1; i <= deadline; i++){
                if(i == 1){
                    firstInterest = amount * monthRate / 100;
                }
                if(i == deadline){
                    repayInterest += (monthPrincipal * monthRate / 100);
                }else{
                    var leftAmount = amount - monthPrincipal * (i - 1);
                    repayInterest += (leftAmount * monthRate / 100);
                }
            }
            bean.firstMonth = Math.round((monthPrincipal + firstInterest) * 100) / 100; // 首月还款
            bean.interestSum = Math.round(repayInterest * 100) / 100; // 总利息
            bean.decrease = Math.round(monthPrincipal * monthRate) / 100; // 每月递减
            bean.sum = Math.round((bean.interestSum + amount)*100)/100; // 本息总和
            return bean;
        }

        //二手房 普通住宅税计算
        function sendHandNormalCalc(bean){
            var result = {};
            result.fanType=1;
            //契税
            if(bean.isFirst ==0){
                result.qTax= (bean.totalAmount*10000*0.03).toFixed(2);
                result.qTaxDesc= '非首次购房,契税为总房价的3%';
            }else if(bean.area <=90){
                result.qTax= (bean.totalAmount*10000*0.01).toFixed(2);
                result.qTaxDesc= '首次购房且面积<=90,契税为总房价的1%';
            }else{
                result.qTax= (bean.totalAmount*10000*0.015).toFixed(2);
                result.qTaxDesc= '首次购房且面积>90,契税为总房价的1.5%';
            }
            //增值税
            result.zzTax=0;
            //都要交增值税
            if(bean.fanYear < 2 ){
                result.zzTax= (bean.totalAmount*10000*0.05/(1+0.05)).toFixed(2);
                result.zzTaxDesc = "购房不满2年，增值税为总房价/(1+5%)*5%";
            }else{
                result.zzTaxDesc = "购房满2年，增值税为0";
            }
            //个税
            result.grTax =0;
            //不是首套或未满5年要交个税
            if(bean.totalAmount-bean.oldAmount<=0){
                result.grTax= 0;
                result.grTaxDesc = '购买价格小于原价,个税为0';
            }else if(bean.fanYear <5){
                result.grTax= ((bean.totalAmount-bean.oldAmount)*10000*0.2).toFixed(2);
                result.grTaxDesc = '购房不满5年，个人所得税为(房屋现总价-房屋原价)*20%';
            }else if(bean.isOnly==0 ){
                result.grTax= ((bean.totalAmount-bean.oldAmount)*10000*0.2).toFixed(2);
                result.grTaxDesc = '购房满5年非卖方唯一，个人所得税为(房屋现总价-房屋原价)*20%';

            }else{
                result.grTaxDesc = '购房满5年，并且卖方唯一，个税为0';
            }
            //印花税
            result.yhTax=5.0;
            result.total = (parseFloat(result.qTax)+parseFloat(result.zzTax)+parseFloat(result.grTax)+result.yhTax).toFixed(2);
            return result;
        }

        //二手房税计算 非普通住宅 totalAmount 为万元
        function sendHandNotNormalCalc(bean){
            var result = {};
            result.fanType=2;
            //契税 =
            result.qTax= (bean.totalAmount*10000*0.015).toFixed(2);
            //增值税
            result.zzTax=0;
            //都要交增值税
            if(bean.fanYear<2 ){
                result.zzTax= (bean.totalAmount*10000*0.05/(1+0.05)).toFixed(2);
                result.zzTaxDesc = "购房不满2年，增值税为房屋现总价/(1+5%)*5%";
            }else{
                result.zzTax= ((bean.totalAmount-bean.oldAmount)*10000*0.05/(1+0.05)).toFixed(2);
                result.zzTaxDesc = "购房满2年，增值税为(房屋现总价-房屋原价)/(1+5%)*5%";
            }
            //个税
            result.grTax =0;
            //不是首套或未满5年要交个税
            if(bean.totalAmount-bean.oldAmount<=0){
                result.grTax= 0;
                result.grTaxDesc = '购买价格小于原价,个税为0';
            }else if(bean.fanYear <5){
                result.grTax= ((bean.totalAmount-bean.oldAmount)*10000*0.2).toFixed(2);
                result.grTaxDesc = '购房不满5年，个人所得税为(房屋现总价-房屋原价)*20%';
            }else if(bean.isOnly==0 ){
                result.grTax= ((bean.totalAmount-bean.oldAmount)*10000*0.2).toFixed(2);
                result.grTaxDesc = '购房满5年非卖方唯一，个人所得税为(房屋现总价-房屋原价)*20%';
            }else{
                result.grTaxDesc = '购房满5年，并且唯一，个人所得税为0';
            }
            //印花税
            result.yhTax=5;
            result.total = (parseFloat(result.qTax)+parseFloat(result.zzTax)+parseFloat(result.grTax)+result.yhTax).toFixed(2);
            return result;
        }
        //二手房税计算 经适房
        function sendHandJSFCalc(bean){
            var result = {};
            result.fanType=1;
            //契税
            if(bean.isFirst ==0){
                result.qTax= (bean.totalAmount*10000*0.03).toFixed(2);
                result.qTaxDesc= '非首次购房,契税为总房价的3%';
            }else {
                result.qTax= (bean.totalAmount*10000*0.015).toFixed(2);
                result.qTaxDesc= '首次购房,契税为总房价的1.5%';
            }
            //个税
            result.grTax =0;
            //不是首套或未满5年要交个税
            if(bean.totalAmount-bean.oldAmount<=0){
                result.grTax= 0;
                result.grTaxDesc = '购买价格小于原价,个税为0';
            }else if(result.isOnly==0 ){
                result.grTax= ((bean.totalAmount-bean.oldAmount)*10000*0.2).toFixed(2);
                result.grTaxDesc = '卖方家庭不唯一住房，个人所得税为(房屋现总价-房屋原价)*20%';
            }else{
                result.grTaxDesc = '卖方唯一住房，个税为0';
            }
            //印花税
            result.yhTax=5;
            //地税
            result.djTax=(bean.totalAmount*10000*0.1).toFixed(2);
            result.djTaxDesc="综合地价税为房屋总价的10%";

            result.total = (parseFloat(result.qTax)+ parseFloat(result.djTax)+parseFloat(result.grTax)+result.yhTax).toFixed(2);
            return result;
        }

        //新房税计算
        function newFeeCalc(bean){
            var result = {};
            result.fanType=1;
            //契税
            if(bean.isFirst ==0){
                result.qTax= (bean.totalAmount*10000*0.03).toFixed(2);
            }else {
                result.qTax= (bean.totalAmount*10000*0.015).toFixed(2);
            }
            //维修
            result.wxAmount =bean.totalAmount*10000*0.02.toFixed(2);
            //交易手续
            result.jyAmount=200;
            //登记费
            result.djAmount = 100;

            result.total = (parseFloat(result.qTax)+parseFloat(result.wxAmount)+result.jyAmount + result.djAmount).toFixed(2);
            return result;
        }
        function my_nan(num, str) {
            if (isNaN(num)) {
                str += '格式不正确';
            } else if(0>=num) {
                str += '不能小于0';
            } else {
                return true;
            }
            XT.error(str);
            return false;
        }
    </script>
    <script src="/home/js/lselect.js"></script>
    <script src="/home/js/ltabs.js"></script>


    <div id="l-main">
        <div class="am-container">
            <div class="calc-entry">
                <ul class="am-cf">
                    <li class="ce-li cel1 cur"><a href="/main/mortgage">购房贷款工具</a></li>
                    <li class="ce-li cel2"><a href="/mian/card">信用卡分期</a></li>
                    <li class="ce-li cel3"><a href="/main/evaluate">贷款能力评估</a></li>
                    <li class="ce-li cel4"><a href="/apply/cardstepone">信用卡快捷推荐</a></li>
                </ul>
            </div>
            <div class="calc-wrap">
                <div class="top">
                    <div class="icon icon1"></div>
                    <div class="t-r">
                        <h3 class="t">购房贷款工具</h3>
                        <p class="p">掌握税费，贷款更加清晰明了</p>
                    </div>
                </div>
                <div class="content am-cf">
                    <div class="con-op">
                        <div class="title">填写信息<span class="st">（均为必填）</span></div>
                        <div class="com-form" id="JS-calctabs">
                            <div class="a-form-group">
                                <label class="a-label">房屋类型</label>
                                <div class="input-wrap">
                                    <a href="/main/mortgage" class="radio-label auto"><i class="icon"></i>商业贷款</a>
                                    <a href="/main/fund" class="radio-label auto cur"><i class="icon"></i>公积金贷款</a>
                                    <a href="/main/group" class="radio-label auto"><i class="icon"></i>组合贷款</a>
                                </div>
                            </div>
                            <form id="JS-calc1">
                                <div class="a-form-group">
                                    <label class="a-label">公积金金额</label>
                                    <div class="input-wrap">
                                        <div class="lfont-input">
                                            <input type="text" id="JS-gjj-amount" placeholder="请输入" min="0">
                                            <label class="lfont-label">万</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="a-form-group">
                                    <label class="a-label">贷款期限</label>
                                    <div class="input-wrap">
                                        <div class="l-select-wrap select-loan-period" name="loan-period"><input type="hidden" name="loan-period" value="10"><input type="text" value="10年" placeholder="请选择" class="l-input " readonly><ul><li data-val="2">2年</li><li data-val="3">3年</li><li data-val="4">4年</li><li data-val="5">5年</li><li data-val="10">10年</li><li data-val="15">15年</li><li data-val="20">20年</li><li data-val="25">25年</li><li data-val="30">30年</li></ul></div>
                                    </div>
                                </div>
                                <div class="a-form-group">
                                    <label class="a-label">公积金利率</label>
                                    <div class="input-wrap">
                                        <input type="hidden" name="gjjRate" value="3.25">
                                        <span class="radio-label ll auto cur gjjRate-radio" data-val="3.25"><i class="icon"></i>标准：3.25%</span>
                                        <span class="radio-label ll auto gjjRate-radio" data-val="3.58"><i class="icon"></i>1.1倍：3.58%</span>
                                    </div>
                                </div>
                                <p class="r-tip2"><i class="icon"></i>2015年10月24日最新商贷利率4.9%，公积金利率3.25%</p>
                                <div class="a-form-group am-padding-top">
                                    <label class="a-label"></label>
                                    <div class="input-wrap">
                                        <input type="button" id="JS-calc" class="btn short btn-reg am-margin-right" value="计算">
                                        <input type="reset" class="btn short" value="重置">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="con-op">
                        <div class="title r">计算结果<span class="st">（计算结果仅供参考）</span></div>
                        <div class="result-content" id="JS-calc-result">
                            <ul class="scr-nav am-cf">
                                <li class="src-li JQ-li cur">等额本息</li>
                                <li class="src-li JQ-li">等额本金</li>
                            </ul>
                            <div class="scr-pane JQ-pane cur">
                                <ul class="rc-box">
                                    <li class="rc-op">
                                        <span class="k">月供</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">总利息</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <div class="rc-op">
                                        <span class="k">本息合计</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </div>
                                    <li class="rc-op">
                                        <span class="k">贷款金额</span>
                                        <span class="v"><i class="orange">0</i>万元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">贷款期限</span>
                                        <span class="v"><i class="orange">0</i>年</span>
                                    </li>
                                </ul>
                            </div>
                            <div class="scr-pane JQ-pane">
                                <ul class="rc-box">
                                    <li class="rc-op">
                                        <span class="k">首次月供</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">每月递减</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">总利息</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">本息合计</span>
                                        <span class="v"><i class="orange">0</i>元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">贷款金额</span>
                                        <span class="v"><i class="orange">0</i>万元</span>
                                    </li>
                                    <li class="rc-op">
                                        <span class="k">贷款期限</span>
                                        <span class="v"><i class="orange">0</i>年</span>
                                    </li>
                                </ul>
                            </div>
                            <p class="r-tip2"><span class="icon"></span>此结果仅供参考，以当地实际情况为准</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="/home/js/lbackTop.js"></script>
    {{--<script type="text/javascript" src="/home/js/ltabs(1).js"></script>--}}
    <script type="text/javascript">
        $("#JS-backtop").Lbacktop();
        $("#JQ-taglink").ltabs({
            navLi: '.nav-tli',
            tabsPane: '.tag-pane',
            lEvent: 'mouseover'
        });
        $(function(){
            if (window.location.hostname == 'www.51finace.com'){
                $("#JS-fyhb-copyright").show();
                $("#JS-xxjr-copyright").hide();
            }
        });
    </script>
    <script>
        $(function(){
            var loanPerJson = [
                {"key":"2年","val":"2"},
                {"key":"3年","val":"3"},
                {"key":"4年","val":"4"},
                {"key":"5年","val":"5"},
                {"key":"10年","val":"10"},
                {"key":"15年","val":"15"},
                {"key":"20年","val":"20"},
                {"key":"25年","val":"25"},
                {"key":"30年","val":"30"},
            ];
            $(".select-loan-period").lselect({
                selectJson : loanPerJson,
                readonly: true,
                defaultText:"10年",
                defaultValue:"10"
            });

            $(".gjjRate-radio").click(function(){
                $(".gjjRate-radio").removeClass("cur");
                $(this).addClass("cur");
                $("input[name='gjjRate']").val($(this).attr("data-val"));
            });


            $("#JS-calc").on("click",function(e){
                var gjjAmount = $("#JS-gjj-amount").val();
                if(gjjAmount == null || $.trim(gjjAmount)==''){
                    layer.alert("公积金贷款金额不能为空!");
                    return;
                }
                var loanPeriod = $("input[name='loan-period']").val();
                var gjjRate = $("input[name='gjjRate']").val();

                var equalInterest = repaySame(gjjAmount*10000,loanPeriod*12,gjjRate/12);
                var	equalAmount = repaySamePrincipal(gjjAmount*10000,loanPeriod*12,gjjRate/12);

                $("#JS-calc-result").template({
                    templateId: "show-calc-result",
                    source:  {equalInterest:equalInterest,
                        equalAmount:equalAmount,
                        loanAmount:gjjAmount,
                        periods:loanPeriod,
                        success:true},
                    data: {success:true},
                    onComplate: function(data){
                        $("#JS-calc-result").ltabs();
                    }
                });
            });
        });
    </script>
    <script type="text/html" id="show-calc-result">
        <ul class="scr-nav am-cf">
            <li class="src-li JQ-li cur">等额本息</li>
            <li class="src-li JQ-li">等额本金</li>
        </ul>
        <div class="scr-pane JQ-pane cur">
            <ul class="rc-box">
                <li class="rc-op">
                    <span class="k">月供</span>
                    <span class="v"><i class="orange">@{{equalInterest.perMonth}}</i>元</span>
                </li>
                <li class="rc-op">
                    <span class="k">总利息</span>
                    <span class="v"><i class="orange">@{{equalInterest.interestSum}}</i>元</span>
                </li>
                <div class="rc-op">
                    <span class="k">本息合计</span>
                    <span class="v"><i class="orange">@{{equalInterest.sum}}</i>元</span>
                </div>
                <li class="rc-op">
                    <span class="k">贷款金额</span>
                    <span class="v"><i class="orange">@{{loanAmount}}</i>万元</span>
                </li>
                <li class="rc-op">
                    <span class="k">贷款期限</span>
                    <span class="v"><i class="orange">@{{periods}}</i>年</span>
                </li>
            </ul>
        </div>
        <div class="scr-pane JQ-pane">
            <ul class="rc-box">
                <li class="rc-op">
                    <span class="k">首次月供</span>
                    <span class="v"><i class="orange">@{{equalAmount.firstMonth}}</i>元</span>
                </li>
                <li class="rc-op">
                    <span class="k">每月递减</span>
                    <span class="v"><i class="orange">@{{equalAmount.decrease}}</i>元</span>
                </li>
                <li class="rc-op">
                    <span class="k">总利息</span>
                    <span class="v"><i class="orange">@{{equalAmount.interestSum}}</i>元</span>
                </li>
                <li class="rc-op">
                    <span class="k">本息合计</span>
                    <span class="v"><i class="orange">@{{equalAmount.sum}}</i>元</span>
                </li>
                <li class="rc-op">
                    <span class="k">贷款金额</span>
                    <span class="v"><i class="orange">@{{loanAmount}}</i>万元</span>
                </li>
                <li class="rc-op">
                    <span class="k">贷款期限</span>
                    <span class="v"><i class="orange">@{{periods}}</i>年</span>
                </li>
            </ul>
        </div>
        <p class="r-tip2"><span class="icon"></span>此结果仅供参考，以当地实际情况为准</p>
    </script>
@endsection